Plotting points

Plotting points

Grades

Grade 2 or higher

Objective

•    Learn about numbers and their relative values
•    Concept of front and back, overlapping
•    Colors and their names
•    Rainbow colors
•    Using different symbols
•    Creating patterns
•    Right-left and up-down coordinates
•    Negative and positive counting
•    Average of two numbers

Prerequisite

Students should be able to

•    Log in to Jupyterhub
•    Open a new notebook
•    Copy text from chat box and paste into a notebook cell
•    Run a cell in the notebook
•    Copy and paste selected texts

Content

•   Copy, paste and run the code to plot a point.
•   Plot multiple points.
•   Change the size, position and color of the points.
•   Create multiple points at the same place and make them larger/smaller to show them all at once.
•   Change the marker of points.
•   Move points to make different patterns.

Description

It uses matplotlib.pyplot to plot points. They are given the first two lines of code and then told to copy and paste them and experiment as follows.

Students are encouraged to experiment with the color, size and position of the points. They plot different sized points at the same place to understand the relative size of points, the concept of overlapping and putting things in front or back.

While moving points right-left or up-down, they learn the concept of coordinates and also negative numbers. To plot midpoints, they learn how to get the average of two points.

They move points and change markers to make beautiful patterns.

Let us get started

Plot a point

In [1]:
import matplotlib.pyplot as plt
In [2]:
plt.plot( 0, 0, marker='o', color='pink', markersize = 50)
Out[2]:
[<matplotlib.lines.Line2D at 0x1f7baec7190>]

Change color

Let them experiment with different colors. Ask students to put the colors of their shirt or top, bottom, color of walls and other things that are present at that time. Thus, they will be able to develop a sense of color.

In [3]:
plt.plot( 0, 0, marker='o', color='green', markersize = 50)
Out[3]:
[<matplotlib.lines.Line2D at 0x1f7bb0f6940>]
In [4]:
plt.plot( 0, 0, marker='o', color='grey', markersize = 50)
Out[4]:
[<matplotlib.lines.Line2D at 0x1f7baf61730>]
In [5]:
plt.plot( 0, 0, marker='o', color='brown', markersize = 50)
Out[5]:
[<matplotlib.lines.Line2D at 0x1f7bafc7220>]

Change size

Let the children experiment. Ask them to try things like negatives, zeros, or even fractions and compare them.

In [6]:
plt.plot( 0, 0, marker='o', color='green', markersize = 150)
Out[6]:
[<matplotlib.lines.Line2D at 0x1f7bb01b610>]
In [7]:
plt.plot( 0, 0, marker='o', color='green', markersize = 10)
Out[7]:
[<matplotlib.lines.Line2D at 0x1f7bb264df0>]
In [8]:
plt.plot( 0, 0, marker='o', color='green', markersize = 50)
Out[8]:
[<matplotlib.lines.Line2D at 0x1f7bb15c310>]
In [9]:
plt.plot( 0, 0, marker='o', color='green', markersize = -50)
Out[9]:
[<matplotlib.lines.Line2D at 0x1f7bb1b5970>]
In [10]:
plt.plot( 0, 0, marker='o', color='green', markersize = 15/4)
Out[10]:
[<matplotlib.lines.Line2D at 0x1f7bb27fd90>]
In [11]:
plt.plot( 0, 0, marker='o', color='green', markersize = .50)
Out[11]:
[<matplotlib.lines.Line2D at 0x1f7bb2ea1c0>]

Use different markers

Square shape

In [12]:
plt.plot( 0, 0, marker='s', color='blue', markersize = 50)
Out[12]:
[<matplotlib.lines.Line2D at 0x1f7bb3434f0>]
In [13]:
plt.plot( 0, 0, marker='s', color='red', markersize = 150)
Out[13]:
[<matplotlib.lines.Line2D at 0x1f7bb39cb50>]
In [14]:
plt.plot( 0, 0, marker='s', color='black', markersize = 100)
Out[14]:
[<matplotlib.lines.Line2D at 0x1f7bc395190>]
In [ ]:
 

Draw triangle

In [15]:
plt.plot( 0, 0, marker='^', color='green', markersize = 50)
Out[15]:
[<matplotlib.lines.Line2D at 0x1f7bc3ecd60>]

Draw Star

In [16]:
plt.plot( 0, 0, marker='*', color='grey', markersize = 50)
Out[16]:
[<matplotlib.lines.Line2D at 0x1f7bc453400>]

Draw Diamond

In [17]:
plt.plot( 0, 0, marker='d', color='orange', markersize = 50)
Out[17]:
[<matplotlib.lines.Line2D at 0x1f7bc4a7670>]
In [ ]:
 

Draw Pentagon

In [18]:
plt.plot( 0, 0, marker='p', color='orange', markersize = 50)
Out[18]:
[<matplotlib.lines.Line2D at 0x1f7bc66fcd0>]

Draw Hexagon

In [19]:
plt.plot( 0, 0, marker='h', color='pink', markersize = 50)
Out[19]:
[<matplotlib.lines.Line2D at 0x1f7bc558340>]

Draw Octagon

In [20]:
plt.plot( 0, 0, marker='8', color='black', markersize = 50)
Out[20]:
[<matplotlib.lines.Line2D at 0x1f7bc5b1670>]

Draw Plus/Cross Sign

In [21]:
plt.plot( 0, 0, marker='P', color='yellow', markersize = 50)
Out[21]:
[<matplotlib.lines.Line2D at 0x1f7bc60cca0>]

Draw Heart Shape

In [22]:
plt.plot( 0, 0, marker=r'$\heartsuit$', color='red', markersize = 40)
Out[22]:
[<matplotlib.lines.Line2D at 0x1f7bd7c52b0>]

List of markers

Having drawn different shapes, show them how to find other markers online.

Draw multiple points

Draw two point at a time

In [23]:
plt.plot( 0, 0, marker='o', color='red', markersize = 100)
plt.plot( 0, 0, marker='s', color='blue', markersize = 100)
Out[23]:
[<matplotlib.lines.Line2D at 0x1f7bc782790>]

Separate them by changing their positions

Let us learn how to position of shapes

In [24]:
plt.plot( 0, 0, marker='o', color='red', markersize = 100)
plt.plot( 0, 30, marker='s', color='blue', markersize = 100)
Out[24]:
[<matplotlib.lines.Line2D at 0x1f7bd933550>]
In [25]:
plt.plot( 0, 0, marker='o', color='red', markersize = 100)
plt.plot( 10, 30, marker='s', color='blue', markersize = 100)
Out[25]:
[<matplotlib.lines.Line2D at 0x1f7bd822a00>]

increase size of the figure

We send three lines of code to copy and paste as it is too early to teach them:

plt.figure(figsize=(10,10))

plt.xlim(-50, 50)
plt.ylim(-50, 50)

Now, we can experiment with left and right, up and down. It is good time to show them what negative and positive numbers do.

Pleace the square to right of the circle

Let us experiment which value will make points move right or let.

In [26]:
plt.figure(figsize=(5,5))

plt.plot( 0, 0, marker='o', color='red', markersize = 10)
plt.plot( 20, 0, marker='s', color='blue', markersize = 10)

plt.xlim(-50, 50)
plt.ylim(-50, 50)
Out[26]:
(-50.0, 50.0)

Pleace the square to left of the circle

In [27]:
plt.figure(figsize=(5,5))

plt.plot( 0, 0, marker='o', color='red', markersize = 10)
plt.plot( -20, 0, marker='s', color='blue', markersize = 10)

plt.xlim(-50, 50)
plt.ylim(-50, 50)
Out[27]:
(-50.0, 50.0)

Pleace the square above the circle

In [28]:
plt.figure(figsize=(5,5))

plt.plot( 0, 0, marker='o', color='red', markersize = 10)
plt.plot( 0, 20, marker='s', color='blue', markersize = 10)

plt.xlim(-50, 50)
plt.ylim(-50, 50)
Out[28]:
(-50.0, 50.0)

Pleace the square below the circle

In [29]:
plt.figure(figsize=(5,5))

plt.plot( 0, 0, marker='o', color='red', markersize = 10)
plt.plot( 0, -20, marker='s', color='blue', markersize = 10)

plt.xlim(-50, 50)
plt.ylim(-50, 50)
Out[29]:
(-50.0, 50.0)

Now experiment with positions

So, we have learned how to move points right-left or up-down. They are called (x, y) pair. x is used for right-left movement and y for up-down movement.

In [30]:
plt.figure(figsize=(5,5))

plt.plot( -5, 20, marker='o', color='red', markersize = 10)
plt.plot( 20, -10, marker='s', color='blue', markersize = 10)

plt.xlim(-50, 50)
plt.ylim(-50, 50)
Out[30]:
(-50.0, 50.0)

All shape together

Assist the children in putting multiple shapes. Ask them to decide the postion of a news shape, left, right, up or down to a shape already drawn, before they draw it.

In [31]:
plt.figure(figsize=(20,10))

plt.plot( 10, 0, marker='o', color='red', markersize = 100)
plt.plot( 10, 30, marker='s', color='blue', markersize = 100)
plt.plot( 10, -30, marker='^', color='green', markersize = 100)

plt.plot( -10, 0, marker='*', color='grey', markersize = 100)
plt.plot( -10, 30, marker='d', color='orange', markersize = 100)
plt.plot( -10, -30, marker='p', color='purple', markersize = 100)

plt.plot( -30, 0, marker='h', color='pink', markersize = 100)
plt.plot( -30, 30, marker='8', color='black', markersize = 100)
plt.plot( -30, -30, marker='P', color='yellow', markersize = 100)

plt.plot( 30, 0, marker=r'$\heartsuit$', color='red', markersize = 100)
plt.plot( 30, 30, marker='>', color='lightgreen', markersize = 100)
plt.plot( 30, -30, marker='v', color='lightblue', markersize = 100)

plt.xlim(-50, 50)
plt.ylim(-50, 50)
Out[31]:
(-50.0, 50.0)

Draw a rainbow pattern

In [32]:
plt.figure(figsize=(10,6))
plt.plot( 0, 0, marker = 'o' , color = 'violet', markersize = 250)
plt.plot( 0, 0, marker = 'o' , color = 'indigo' , markersize = 240)
plt.plot( 0, 0, marker = 'o' , color = 'blue' , markersize = 230)
plt.plot( 0, 0, marker = 'o' , color = 'green' , markersize = 220)
plt.plot( 0, 0, marker = 'o' , color = 'yellow' , markersize = 210)
plt.plot( 0, 0, marker = 'o' , color = 'orange' , markersize = 200)
plt.plot( 0, 0, marker = 'o' , color = 'red' , markersize = 190)



plt.xlim(-4, 4)
plt.ylim(-4, 4)
plt.show()

Adjust markersize to make them look better

In [33]:
plt.figure(figsize=(10,6))

plt.plot( 0, 0, marker = 'o' , color = 'violet', markersize = 250)
plt.plot( 0, 0, marker = 'o' , color = 'indigo' , markersize = 220)
plt.plot( 0, 0, marker = 'o' , color = 'blue' , markersize = 190)
plt.plot( 0, 0, marker = 'o' , color = 'green' , markersize = 160)
plt.plot( 0, 0, marker = 'o' , color = 'yellow' , markersize = 130)
plt.plot( 0, 0, marker = 'o' , color = 'orange' , markersize = 100)
plt.plot( 0, 0, marker = 'o' , color = 'red' , markersize = 70)


plt.xlim(-4, 4)
plt.ylim(-4, 4)
plt.show()

Move shapes to create different patterns

In [34]:
plt.figure(figsize=(10,6))

plt.plot( 0, 0, marker = 'o' , color = 'violet', markersize = 250)
plt.plot( 0, 0, marker = 'o' , color = 'indigo' , markersize = 220)
plt.plot( 0, 0, marker = 'o' , color = 'blue' , markersize = 190)
plt.plot( 0, 0, marker = 'o' , color = 'green' , markersize = 160)
plt.plot( 0, 0, marker = 'o' , color = 'yellow' , markersize = 130)
plt.plot( 0, 0, marker= 'o' , color = 'orange' , markersize = 100)
plt.plot( 5, 0, marker = 'o' , color = 'red' , markersize = 70)

plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.show()
In [35]:
plt.figure(figsize=(10,6))

plt.plot( -1, 0, marker = 'o' , color = 'violet', markersize = 250)
plt.plot( -2, 0, marker = 'o' , color = 'indigo' , markersize = 220)
plt.plot( -3, 0, marker = 'o' , color = 'blue' , markersize = 190)
plt.plot( -4, 0, marker = 'o' , color = 'green' , markersize = 160)
plt.plot( -5, 0, marker = 'o' , color = 'yellow' , markersize = 130)
plt.plot( -6, 0, marker = 'o' , color = 'orange' , markersize = 100)
plt.plot( -7, 0, marker = 'o' , color = 'red' , markersize = 70)

plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.show()
In [36]:
plt.figure(figsize=(10,6))

plt.plot( 1, 0, marker = 'o' , color = 'violet', markersize = 250)
plt.plot( 2, 0, marker = 'o' , color = 'indigo' , markersize = 220)
plt.plot( 3, 0, marker = 'o' , color = 'blue' , markersize = 190)
plt.plot( 4, 0, marker = 'o' , color = 'green' , markersize = 160)
plt.plot( 5, 0, marker = 'o' , color = 'yellow' , markersize = 130)
plt.plot( 6, 0, marker = 'o' , color = 'orange' , markersize = 100)
plt.plot( 7, 0, marker = 'o' , color = 'red' , markersize = 70)

plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.show()
In [37]:
plt.figure(figsize=(10,6))

plt.plot( 0, -1, marker = 'o' , color = 'violet', markersize = 250)
plt.plot( 0, -2, marker = 'o' , color = 'indigo' , markersize = 220)
plt.plot( 0, -3, marker = 'o' , color = 'blue' , markersize = 190)
plt.plot( 0, -4, marker = 'o' , color = 'green' , markersize = 160)
plt.plot( 0, -5, marker = 'o' , color = 'yellow' , markersize = 130)
plt.plot( 0, -6, marker = 'o' , color = 'orange' , markersize = 100)
plt.plot( 0, -7, marker = 'o' , color = 'red' , markersize = 70)

plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.show()

Chnage marker to see how same pattern looks different

In [38]:
plt.figure(figsize=(10,6))

plt.plot( 0, -1, marker = 's' , color = 'red', markersize = 250)
plt.plot( 0, -2, marker = 's' , color = 'orange' , markersize = 220)
plt.plot( 0, -3, marker = 's' , color = 'yellow' , markersize = 190)
plt.plot( 0, -4, marker = 's' , color = 'green' , markersize = 160)
plt.plot( 0, -5, marker = 's' , color = 'blue' , markersize = 130)
plt.plot( 0, -6, marker = 's' , color = 'indigo' , markersize = 100)
plt.plot( 0, -7, marker = 's' , color = 'violet' , markersize = 70)

plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.show()
In [39]:
plt.figure(figsize=(10,6))

plt.plot( 0, 0, marker = '*' , color = 'darkblue', markersize = 250)
plt.plot( 0, 0, marker = '*' , color = 'greenyellow' , markersize = 220)
plt.plot( 0, 0, marker = '*' , color = 'yellow' , markersize = 190)
plt.plot( 0, 0, marker = '*' , color = 'green' , markersize = 160)
plt.plot( 0, 0, marker = '*' , color = 'blue' , markersize = 130)
plt.plot( 0, 0, marker = '*' , color = 'indigo' , markersize = 100)
plt.plot( 0, 0, marker = '*' , color = 'violet' , markersize = 70)
plt.plot( 0, 0, marker = '*' , color = 'green' , markersize = 40)
plt.plot( 0, 0, marker = '*' , color = 'darkorange' , markersize = 20)

plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.show()
In [40]:
plt.figure(figsize=(10,10))

plt.plot( 0, 0, marker="$\u2665$", color = 'tomato', markersize = 350)
plt.plot( 0, 0, marker="$\u2665$", color = 'deeppink', markersize = 320)
plt.plot( 0, 0, marker="$\u2665$", color = 'crimson', markersize = 290)
plt.plot( 0, 0, marker="$\u2665$", color = 'purple', markersize = 250)
plt.plot( 0, 0, marker="$\u2665$", color = 'orange' , markersize = 220)
plt.plot( 0, 0, marker="$\u2665$", color = 'yellow' , markersize = 190)
plt.plot( 0, 0, marker="$\u2665$", color = 'green' , markersize = 160)
plt.plot( 0, 0, marker="$\u2665$", color = 'blue' , markersize = 130)
plt.plot( 0, 0, marker="$\u2665$", color = 'indigo' , markersize = 100)
plt.plot( 0, 0, marker="$\u2665$", color = 'violet' , markersize = 70)
plt.plot( 0, 0, marker="$\u2665$", color = 'red' , markersize = 40)

plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.show()
In [41]:
plt.figure(figsize=(10,10))

plt.plot( 0, -1, marker="$\u2665$", color = 'tomato', markersize = 350)
plt.plot( 0, -2, marker="$\u2665$", color = 'deeppink', markersize = 320)
plt.plot( 0, -3, marker="$\u2665$", color = 'crimson', markersize = 290)
plt.plot( 0, -4, marker="$\u2665$", color = 'purple', markersize = 250)
plt.plot( 0, -5, marker="$\u2665$", color = 'orange' , markersize = 220)
plt.plot( 0, -6, marker="$\u2665$", color = 'yellow' , markersize = 190)
plt.plot( 0, -7, marker="$\u2665$", color = 'green' , markersize = 160)
plt.plot( 0, -8, marker="$\u2665$", color = 'blue' , markersize = 130)
plt.plot( 0, -9, marker="$\u2665$", color = 'indigo' , markersize = 100)

plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.show()
In [ ]:
 

That's it for now. Happy learning!

Knowledge Management: No Rote Learning

Brought to you by XcelVations. If you want to learn more about our courses and learning modules, visit http://xcelvations.com/

In [ ]:
 

Machine Learning

  1. Deal Banking Marketing Campaign Dataset With Machine Learning

TensorFlow

  1. Difference Between Scalar, Vector, Matrix and Tensor
  2. TensorFlow Deep Learning Model With IRIS Dataset
  3. Sequence to Sequence Learning With Neural Networks To Perform Number Addition
  4. Image Classification Model MobileNet V2 from TensorFlow Hub
  5. Step by Step Intent Recognition With BERT
  6. Sentiment Analysis for Hotel Reviews With NLTK and Keras
  7. Simple Sequence Prediction With LSTM
  8. Image Classification With ResNet50 Model
  9. Predict Amazon Inc Stock Price with Machine Learning
  10. Predict Diabetes With Machine Learning Algorithms
  11. TensorFlow Build Custom Convolutional Neural Network With MNIST Dataset
  12. Deal Banking Marketing Campaign Dataset With Machine Learning

PySpark

  1. How to Parallelize and Distribute Collection in PySpark
  2. Role of StringIndexer and Pipelines in PySpark ML Feature - Part 1
  3. Role of OneHotEncoder and Pipelines in PySpark ML Feature - Part 2
  4. Feature Transformer VectorAssembler in PySpark ML Feature - Part 3
  5. Logistic Regression in PySpark (ML Feature) with Breast Cancer Data Set

PyTorch

  1. Build the Neural Network with PyTorch
  2. Image Classification with PyTorch
  3. Twitter Sentiment Classification In PyTorch
  4. Training an Image Classifier in Pytorch

Natural Language Processing

  1. Spelling Correction Of The Text Data In Natural Language Processing
  2. Handling Text For Machine Learning
  3. Extracting Text From PDF File in Python Using PyPDF2
  4. How to Collect Data Using Twitter API V2 For Natural Language Processing
  5. Converting Text to Features in Natural Language Processing
  6. Extract A Noun Phrase For A Sentence In Natural Language Processing